<!DOCTYPE html>
<html lang="en">

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>添加课程</title>
    <link href="/css/style.css" rel="stylesheet" type="text/css" />
    <script src="/js/vue3.js"></script>
    <script src="/js/axios.min.js"></script>
</head>

<body>
    <div class="place">
        <span>位置：</span>
        <ul class="placeul">
            <li><a href="#">课程管理</a></li>
            <li><a href="#">添加课程</a></li>
        </ul>
    </div>
    <div class="formbody" id="box">
        <!-- 工具栏 -->
        <div class="tools">
            <ul class="toolbar">
                <li v-on:click="goback()"><span><img src="/images/t04.png" /></span>返回</li>
            </ul>
        </div>
        <!-- 数据列表 -->
        <form id="uploadForm">
            <div class="formtitle"><span>添加课程</span></div>
            <ul class="forminfo">
                <li><label>课程标题</label><input type="text" class="dfinput" v-model="title" /></li>
                <li><label>课程图片</label><input name="imgurl" type="file" multiple="multiple" ref="uploadimg"
                        class="offset10 lf" /></li>
                <li><label>课程售价</label><input type="text" class="dfinput" v-model="money" /></li>
                <li><label>开始时间</label><input type="date" class="dfinput" v-model="begindate" /></li>
                <li><label>结束时间</label><input type="date" class="dfinput" v-model="enddate" />
                </li>
                <li><label>内容</label><textarea type="text" class="dfinput" v-model="content"></textarea>
                </li>
                <li><label>状态</label><input type="text" class="dfinput" v-model="cstatus" />
                </li>
                <li><label>备注</label><input type="text" class="dfinput" v-model="remark"></li>
            </ul>
            <input type="button" class="scbtn" v-on:click="insertCourse" value="添加">
        </form>
    </div>

    <script>
        var paras = location.search; //search获得地址中的参数，内容为'?itemId=12'
        var temp = paras.split('=');
        var itemId = temp[1];
        var obj = {
            data () {
                return {
                    title: '',
                    money: '',
                    begindate: '',
                    enddate: '',
                    content: '',
                    cstatus: '',
                    remark: '',
                }
            },
            methods: {
                goback () {
                    window.history.back();
                },
                insertCourse () {
                    const formData = new FormData();
                    formData.append('imgurl', vm.$refs.uploadimg.files[0]);
                    formData.append('title', vm.title);
                    formData.append('money', vm.money);
                    formData.append('begindate', vm.begindate);
                    formData.append('enddate', vm.enddate);
                    formData.append('content', vm.content);
                    formData.append('cstatus', vm.cstatus);
                    formData.append('remark', vm.remark);
                    axios({
                        method: 'post',
                        url: '/blog/course/root/',
                        data: formData
                    }).then(function (result) {
                        window.alert(result.data.msg);
                        if (result.data.code == 0) {
                            setTimeout(function () {
                                window.location.href = "/admin_course_manage/course_list.html";
                            }, 500);
                        }
                    });
                }
            }
        }
        var vm = Vue.createApp(obj).mount("#box");
    </script>

</body>

</html>